/**
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function(strs) {
  let result = strs[0];
  for(let i = 1; i < strs.length; i++) {
    if(strs[i].length == 0)
      return "";
    for(let j = 0; j < strs[i].length && j < result.length; j++) {
      if(result[j] != strs[i][j]) {
        result = result.slice(0, j);
        break;
      }
      if(j == strs[i].length - 1 || j == result.length - 1)
        result = result.slice(0, j + 1);
    }
  }
  return result;
};
let strs = ["flower","flow","flight"];
console.log(longestCommonPrefix(strs));
strs = ["dog","racecar","car"];
console.log(longestCommonPrefix(strs));
strs = ["abab","aba",""];
console.log(longestCommonPrefix(strs));
